package com.ktty.service;

import com.ktty.entity.SysUser;
import com.ktty.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


import java.util.List;

@Service("sysUserService")
@Transactional(isolation=Isolation.DEFAULT,propagation=Propagation.REQUIRED,
        readOnly=false,timeout=-1)
public class SysUserServiceImpl implements SysUserService{
    @Autowired
    private SysUserMapper sysUserMapper;

    @Transactional(isolation=Isolation.DEFAULT,propagation=Propagation.REQUIRED,
            readOnly=false,timeout=-1)

    @Override
    public List<SysUser> getUserList(SysUser sysUser) {
        return sysUserMapper.getUserList(sysUser);
    }

    @Override
    public int saveBatch(List<SysUser> sysUserList) {
        int rows = 0;
        for(int i=0; i<sysUserList.size(); i++){
            //拿出每一条用户数据插入
            SysUser sysUser = sysUserList.get(i);
            if(i==1){
                throw new RuntimeException("数据库异常");
            }
            rows += sysUserMapper.insert(sysUser);
        }
        return rows;
    }
}
